package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsName   string  `gorm:"type:varchar(50);not null;"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2);not null"`
	GoodsNum    int64   `gorm:"typer:int"`
	GoodsImg    string  `gorm:"type:varchar(255);not null;"`
	GoodsStatus int64   `gorm:"type:int"` //1精品推荐 2人气热卖 3精选套餐
}

func (g *Goods) FindGoodsByStatus(status int64) (goods []*Goods, err error) {
	err = DB.Where("goods_status=?", status).Find(&goods).Error
	if err != nil {
		return nil, err
	}
	return goods, nil
}
func (g *Goods) FindUserById(id int64) (*Goods, error) {
	err := DB.Where("id=?", id).Find(&g).Error
	if err != nil {
		return nil, err
	}
	return g, nil
}
func (g *Goods) UpdateGoodsNum(id int64, num int64) error {
	err := DB.Model(&g).Where("id=?", id).Update("goods_num", num).Error
	if err != nil {
		return err
	}
	return nil
}
